let fqa_list = document.querySelectorAll('.fqa_item')

// 是否只能展开一个面板
let is_one = 1

// 默认展开
let default_index = 0

fqa_list.forEach((item, index) => {
  if(index == default_index){
      spread(item)
  }

  item.addEventListener('click', function () {
    if (is_one) {
      fqa_list.forEach(el => {
        if (el.classList.contains('active') && el != item) {
          packUp(el)
        }
      })
      if (item.classList.contains('active')) {
        packUp(item)
      } else {
        spread(item)
      }
      return
    }

    if (item.classList.contains('active')) {
      packUp(item)
    } else {
      spread(item)
    }

  })
})

// 展开
function spread(el) {
  let fqa_item_height = parseInt(window.getComputedStyle(el, null).height)
  let a_height = parseInt(window.getComputedStyle(el.lastElementChild, null).height)
  el.style.height = (fqa_item_height + a_height) + 'px'
  el.classList.add('active')
}

// 收起
function packUp(el) {
  // let fqa_item_height = parseInt(window.getComputedStyle(el, null).height)
  // let a_height = parseInt(window.getComputedStyle(el.lastElementChild, null).height)
  // el.style.height = (fqa_item_height - a_height) + 'px'
  el.style.height = '85px'
  el.classList.remove('active')
}


let radio_list = document.querySelectorAll('.input_radio')
// 单选变换监听
function radioChange(e) {
  is_one = Number(e.value)
  radio_list.forEach(item => {
    if (item.value == is_one) {
      item.checked = true
    } else {
      item.checked = false
    }
  })
}

let input = document.querySelector('.input_number')
input.value = default_index

function inputHandle(e){
  if(e.value > fqa_list.length - 1){
    default_index = fqa_list.length - 1
    e.value = default_index
  }else{
    default_index = e.value
  }
  if(!e.value || e.value < 0){
    e.value = 0
    default_index = 0
  }

  let item = fqa_list[default_index]
  if (is_one) {
    fqa_list.forEach(el => {
      if (el.classList.contains('active') && el != item) {
        packUp(el)
      }
    })
    if (item.classList.contains('active')) {
      packUp(item)
    } else {
      spread(item)
    }
    return
  }
  if (item.classList.contains('active')) {
    packUp(item)
  } else {
    spread(item)
  }

}